package com.tools;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;



public class WaitUtil {

    //驱动
    private static WebDriver driver;
    //实例等待
    private static WebDriverWait wait;




    /**
     * 隐式等待方法
     * @param seconds 等待时间（秒）
     */
    public static void implicitWait(int seconds) {
        driver.manage().timeouts().implicitlyWait(seconds, TimeUnit.SECONDS);
    }

    /**
     * 显式等待方法
     * @param by 定位元素的方式
     * @param seconds 等待时间（秒）
     */
    public static void explicitWait(By by, int seconds) {
        wait = new WebDriverWait(driver, seconds);
        wait.until(ExpectedConditions.visibilityOfElementLocated(by));
    }

    /**\
     * 强制等待方法
     * @param seconds
     */
    public static void forcedWaiting(int seconds){
        try {
            TimeUnit.SECONDS.sleep(seconds);
        } catch (InterruptedException e) {
           e.printStackTrace();
        }
    }

}
